import {
    CHANGE_LEFT_LIST,
    CHANGE_CURRENT_INDEX,
    CHANGE_PLAY_LIST_DETAIL,
} from "./constants";
import {
    getRankingList,
    getPlayListDetail
} from "@/services/ranking";

export const changeLeftRankingListAction = (list) => {
    return {
        type: CHANGE_LEFT_LIST,
        list
    }
}

export const changeCurrentIndexAction = (index) => {
    return {
        type: CHANGE_CURRENT_INDEX,
        index
    }
}

export const changePlayListDetailAction = (playlist) => {
    return {
        type: CHANGE_PLAY_LIST_DETAIL,
        playlist
    }
}


//对外暴露的接口请求action
export const getLeftRankingListAction = () => {
    return dispatch => {
        getRankingList().then(res => {
            dispatch(changeLeftRankingListAction(res.list))
        })
    }
}

export const getPlayListDetailAction = (id) => {
    return dispatch => {
        getPlayListDetail(id).then(res => {
            dispatch(changePlayListDetailAction(res.playlist))
        })
    }
}